package com.itheima.web.controller.ums;

import com.itheima.service.ums.ResourceCategoryService;
import com.itheima.utils.ResultData;
import com.itheima.vo.ums.ResourceCategory;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("resourceCategory")
public class ResourceCategoryController {


    @DubboReference
    private ResourceCategoryService resourceCategoryService;


    /**
     * 添加后台资源分类
     * @param resourceCategory
     * @return
     */
    @PostMapping("/create")
    public ResultData saveBrand (@RequestBody ResourceCategory resourceCategory){
        log.info("resourceCategory:{}", resourceCategory);
        return resourceCategoryService.insert(resourceCategory);
    }


    /**
     * 根据ID删除后台资源
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResultData delete(@PathVariable  Integer id ){
        log.info("deleteId:{}",id);
        resourceCategoryService.removeById(id);
        return ResultData.ok("删除成功","ok");
    }


    /*
    获取全部品牌列表
    */
    @GetMapping("/listAll")
    public ResultData listAll ( ){
        List<ResourceCategory> list = resourceCategoryService.list();
        return ResultData.ok("OK" ,list );
    }



    /**
     *修改后台资源
     * @param id
     * @param resourceCategory
     * @return
     */
    @PostMapping("update/{id}")
    public ResultData updateById(@PathVariable Integer id, @RequestBody ResourceCategory resourceCategory){
        resourceCategory.setId(id);
        resourceCategoryService.updateById(resourceCategory);
        return ResultData.ok("操作成功","");
    }
}
